<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="UTF-8"/>
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <title>青芽医疗管理平台</title>
<!--    <meta content="数据采集分析系统" name="description">
    <meta content="数据采集分析系统" name="keywords">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">-->

</head>
<body class="hold-transition">

<div id="app">
    <el-descriptions title="用户登录信息" direction="horizontal" :column="2" border>
        <el-descriptions-item label="用户头像" :span="2">
            <el-image :src="user.photoUrl" style="width: 100px;height: 100px"></el-image>
        </el-descriptions-item>
        <el-descriptions-item label="用户名">{{user.username}}</el-descriptions-item>
        <el-descriptions-item label="姓名">{{user.name}}</el-descriptions-item>
        <el-descriptions-item label="性别">{{user.sex}}</el-descriptions-item>
        <el-descriptions-item label="年龄">{{user.age}}</el-descriptions-item>
        <el-descriptions-item label="出生日期">{{user.birthday}}</el-descriptions-item>
        <el-descriptions-item label="电话号码">{{user.phone}}</el-descriptions-item>
    </el-descriptions>
    <br/>
    <br/>
    <el-button type="primary" @click="handleAdd" v-if="!flag">添加用户就诊信息</el-button>
    <el-button type="primary" @click="handleUpdate" v-if="flag">修改用户就诊信息</el-button>
    <br/>
    <br/>
    <el-descriptions title="用户就诊信息" direction="horizontal" :column="2" border v-if="flag">
        <el-descriptions-item label="姓名">{{patients.patientName}}</el-descriptions-item>
        <el-descriptions-item label="性别">{{patients.patientGender}}</el-descriptions-item>
        <el-descriptions-item label="出生日期">{{patients.formatPatientBirthday}}</el-descriptions-item>
        <el-descriptions-item label="身份证号">{{patients.patientCardId}}</el-descriptions-item>
        <el-descriptions-item label="电话号码">{{patients.patientPhone}}</el-descriptions-item>
        <el-descriptions-item label="家庭住址">{{patients.patientAddress}}</el-descriptions-item>
        <el-descriptions-item label="医保卡" :span="2">{{patients.patientHealthInsuranceCard}}</el-descriptions-item>
        <el-descriptions-item label="创建时间">{{patients.formatPatientCreateTime}}</el-descriptions-item>
        <el-descriptions-item label="修改时间">{{patients.formatPatientUpdateTime}}</el-descriptions-item>
    </el-descriptions>

    <div class="add-form">
        <el-dialog title="添加就诊信息" :visible.sync="dialogFormVisible"  width="760px" :close-on-click-modal="false">
            <el-form ref="dataEditForm" :model="patient"  label-position="right" label-width="100px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="姓名" prop="patientName">
                            <el-input v-model="patient.patientName"/>
                        </el-form-item>
                        <el-form-item label="出生日期" prop="patientBirthday">
                            <el-date-picker v-model="patient.patientBirthday" type="date" placeholder="选择日期"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="电话号码" prop="patientPhone">
                            <el-input v-model="patient.patientPhone" ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="性别" prop="patientGender">
                            <el-radio-group v-model="patient.patientGender">
                                <el-radio label="男"></el-radio>
                                <el-radio label="女"></el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="身份证号" prop="patientCardId">
                            <el-input v-model="patient.patientCardId"></el-input>
                        </el-form-item>
                        <el-form-item label="家庭住址" prop="patientAddress">
                            <el-input v-model="patient.patientAddress"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item label="医保卡" prop="patientHealthInsuranceCard">
                        <el-input v-model="patient.patientHealthInsuranceCard"></el-input>
                    </el-form-item>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取消</el-button>
                <el-button type="primary" @click="addPatient()">确定</el-button>
            </div>
        </el-dialog>
    </div>

    <div class="add-form">
        <el-dialog title="编辑就诊信息" :visible.sync="dialogFormVisible4Edit"  width="760px" :close-on-click-modal="false">
            <el-form ref="dataEditForm" :model="patient"  label-position="right" label-width="100px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="姓名" prop="patientName">
                            <el-input v-model="patient.patientName"/>
                        </el-form-item>
                        <el-form-item label="出生日期" prop="patientBirthday">
                            <el-date-picker v-model="patient.patientBirthday" type="date" placeholder="选择日期"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="电话号码" prop="patientPhone">
                            <el-input v-model="patient.patientPhone" ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="性别" prop="patientGender">
                            <el-radio-group v-model="patient.patientGender">
                                <el-radio label="男"></el-radio>
                                <el-radio label="女"></el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="身份证号" prop="patientCardId">
                            <el-input v-model="patient.patientCardId"></el-input>
                        </el-form-item>
                        <el-form-item label="家庭住址" prop="patientAddress">
                            <el-input v-model="patient.patientAddress"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item label="医保卡" prop="patientHealthInsuranceCard">
                        <el-input v-model="patient.patientHealthInsuranceCard"></el-input>
                    </el-form-item>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                <el-button type="primary" @click="updatePatient()">确定</el-button>
            </div>
        </el-dialog>
    </div>
</div>

</body>
<!-- 引入组件库 -->
<script src="js/vue.js"></script>
<!--<script src="element-ui/lib/index.js"></script>-->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
<script src="js/axios-0.18.0.js"></script>
<!-- 引入样式 -->
<!--<link href="element-ui/lib/theme-chalk/index.css" rel="stylesheet">-->
<script type="application/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            user:{},
            patients:{},
            patient:{},
            flag:false,
            dialogFormVisible: false,
            dialogFormVisible4Edit: false,
        },
        mounted() {
            this.getUser();
        },
        methods: {
            getUser(){
                axios.post('/user/getSessionUser').then(res => {
                    this.user = res.data;
                    console.log(this.user);
                    axios.post('/patient/getPatientByUserId?userId='+this.user.userId).then(r => {
                        if(r.data==""){
                            this.flag = false;
                            this.$message.error('该用户没有就诊信息！需要添加就诊信息才能挂号！');
                        }else {
                            this.patients = r.data;
                            this.flag = true;
                        }
                    });
                });
            },
            handleAdd(){
              this.dialogFormVisible = true;
              this.patient = {}
            },
            handleUpdate(){
                this.dialogFormVisible4Edit = true;
                axios.post('/patient/getById?id='+this.patients.patientId).then(res=>{
                    this.patient = res.data;
                });
            },
            addPatient(){
                this.patient.userId = this.user.userId;
                axios.post('/patient/addPatient', "patient="+JSON.stringify(this.patient)).then(res=>{
                    this.dialogFormVisible=false;
                    if(res){
                        this.$message({
                            type:'success',
                            message:"添加成功"
                        });
                    }else {
                        this.$message.error("添加失败");
                    }
                    this.getUser();
                });
            },
            updatePatient(){
                axios.post('/patient/updatePatient', "patient="+JSON.stringify(this.patient)).then(res=>{
                    this.dialogFormVisible4Edit=false;
                    if(res){
                        this.$message({
                            type:'success',
                            message:"修改成功"
                        });
                    }else {
                        this.$message.error("修改失败");
                    }
                    this.getUser();
                });
            },
        },
    })
</script>
</html>